package com.pengtu.entity.detect;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import com.pengtu.utils.MathsUtils;

/**
 * 路基工程
 * Structurespot.
 */
@Entity
@Table(name = "S_Q_DETECT_STRUCTURESPOT")
public class StructureSpot {

	/**
	 * serialVersionUID:TODO
	 * 
	 * @since 1.0.0
	 */

	private static final long serialVersionUID = 1L;
	private String projectId; // 工程
	private Integer countF201;//路基弯沉抽检点数 
	private Integer passF201;//路基弯沉合格点数
	private Integer countF202;//  路基压实度抽检点数 
	private Integer passF202;//  路基压实度抽检点数 
	private Integer countF203;//  小桥涵混凝土强度检点数 
	private Integer passF203;//小桥涵混凝土强度抽检点数 
	private Integer countF204;//支挡工程砂浆及混凝土强度抽检点数 
	private Integer passF204;//支挡工程砂浆及混凝土强度抽检点数 
	private Integer countF205;//支挡工程断面尺寸抽检点数 
	private Integer passF205;//支挡工程断面尺寸抽检点数 
	private Integer countF206;//排水工程铺砌厚度及断面尺寸抽检点数 
	private Integer passF206;//排水工程铺砌厚度 及断面尺寸抽检点数 
	private Integer countF207;//小桥涵主要结构尺寸抽检点数 
	private Integer passF207;//小桥涵主要结构尺寸抽检点数 
	private Date reportdate;
	private String remark;
	private SpotReport spotReport;
	private String id;
	private String groupBy;
	
	private Date createDate; // 创建时间

	public StructureSpot(){
		
	}
	
	public StructureSpot(Long countF201, Long passF201, Long countF202,
			Long passF202, Long countF203, Long passF203,
			Long countF204, Long passF204, Long countF205,
			Long passF205, Long countF206, Long passF206,
			Long countF207, Long passF207,String groupBy) {
		this.countF201 = countF201 == null ? null : countF201.intValue();
		this.passF201 = passF201 == null ? null : passF201.intValue();
		this.countF202 = countF202 == null ? null : countF202.intValue();
		this.passF202 = passF202 == null ? null : passF202.intValue();
		this.countF203 = countF203 == null ? null : countF203.intValue();
		this.passF203 = passF203 == null ? null : passF203.intValue();
		this.countF204 = countF204 == null ? null : countF204.intValue();
		this.passF204 = passF204 == null ? null : passF204.intValue();
		this.countF205 = countF205 == null ? null : countF205.intValue();
		this.passF205 = passF205 == null ? null : passF205.intValue();
		this.countF206 = countF206 == null ? null : countF206.intValue();
		this.passF206 = passF206 == null ? null : passF206.intValue();
		this.countF207 = countF207 == null ? null : countF207.intValue();
		this.passF207 = passF207 == null ? null : passF207.intValue();
		this.groupBy = groupBy;
	}
	
	public StructureSpot(Long countF201, Long passF201, Long countF202,
			Long passF202, Long countF203, Long passF203,
			Long countF204, Long passF204, Long countF205,
			Long passF205, Long countF206, Long passF206,
			Long countF207, Long passF207) {
		this.countF201 = countF201 == null ? null : countF201.intValue();
		this.passF201 = passF201 == null ? null : passF201.intValue();
		this.countF202 = countF202 == null ? null : countF202.intValue();
		this.passF202 = passF202 == null ? null : passF202.intValue();
		this.countF203 = countF203 == null ? null : countF203.intValue();
		this.passF203 = passF203 == null ? null : passF203.intValue();
		this.countF204 = countF204 == null ? null : countF204.intValue();
		this.passF204 = passF204 == null ? null : passF204.intValue();
		this.countF205 = countF205 == null ? null : countF205.intValue();
		this.passF205 = passF205 == null ? null : passF205.intValue();
		this.countF206 = countF206 == null ? null : countF206.intValue();
		this.passF206 = passF206 == null ? null : passF206.intValue();
		this.countF207 = countF207 == null ? null : countF207.intValue();
		this.passF207 = passF207 == null ? null : passF207.intValue();
	}
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(length = 48)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(nullable = false, updatable = false, name = "CREATEDATE")
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
	@JoinColumn(name = "SID")
	public SpotReport getSpotReport() {
		return spotReport;
	}

	public void setSpotReport(SpotReport spotReport) {
		this.spotReport = spotReport;
	}


	@Column(name = "COUNT_F201")
	public Integer getCountF201() {
		return this.countF201;
	}

	public void setCountF201(Integer countF201) {
		this.countF201 = countF201;
	}

	@Column(name = "PASS_F201")
	public Integer getPassF201() {
		return this.passF201;
	}

	public void setPassF201(Integer passF201) {
		this.passF201 = passF201;
	}

	@Column(name = "PID")
	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	@Column(name = "COUNT_F202")
	public Integer getCountF202() {
		return this.countF202;
	}

	public void setCountF202(Integer countF202) {
		this.countF202 = countF202;
	}

	@Column(name = "PASS_F202")
	public Integer getPassF202() {
		return this.passF202;
	}

	public void setPassF202(Integer passF202) {
		this.passF202 = passF202;
	}

	@Column(name = "COUNT_F203")
	public Integer getCountF203() {
		return this.countF203;
	}

	public void setCountF203(Integer countF203) {
		this.countF203 = countF203;
	}

	@Column(name = "PASS_F203")
	public Integer getPassF203() {
		return this.passF203;
	}

	public void setPassF203(Integer passF203) {
		this.passF203 = passF203;
	}

	@Column(name = "COUNT_F204")
	public Integer getCountF204() {
		return this.countF204;
	}

	public void setCountF204(Integer countF204) {
		this.countF204 = countF204;
	}

	@Column(name = "PASS_F204")
	public Integer getPassF204() {
		return this.passF204;
	}

	public void setPassF204(Integer passF204) {
		this.passF204 = passF204;
	}

	@Column(name = "COUNT_F205")
	public Integer getCountF205() {
		return this.countF205;
	}

	public void setCountF205(Integer countF205) {
		this.countF205 = countF205;
	}

	@Column(name = "PASS_F205")
	public Integer getPassF205() {
		return this.passF205;
	}

	public void setPassF205(Integer passF205) {
		this.passF205 = passF205;
	}

	@Column(name = "COUNT_F206")
	public Integer getCountF206() {
		return this.countF206;
	}

	public void setCountF206(Integer countF206) {
		this.countF206 = countF206;
	}

	@Column(name = "PASS_F206")
	public Integer getPassF206() {
		return this.passF206;
	}

	public void setPassF206(Integer passF206) {
		this.passF206 = passF206;
	}

	@Column(name = "COUNT_F207")
	public Integer getCountF207() {
		return this.countF207;
	}

	public void setCountF207(Integer countF207) {
		this.countF207 = countF207;
	}

	@Column(name = "PASS_F207")
	public Integer getPassF207() {
		return this.passF207;
	}

	public void setPassF207(Integer passF207) {
		this.passF207 = passF207;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "REPORTDATE")
	public Date getReportdate() {
		return this.reportdate;
	}

	public void setReportdate(Date reportdate) {
		this.reportdate = reportdate;
	}

	@Column(name = "REMARK")
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Transient
	public Double getPassrateF201() {
		Double a = MathsUtils.div("2", getPassF201(), getCountF201(), 0.01);
		if(a==0){
			a = null;
		}
		return a;

	}

	@Transient
	public Double getPassrateF202() {
		Double a = MathsUtils.div("2", getPassF202(), getCountF202(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF203() {
		Double a = MathsUtils.div("2", getPassF203(), getCountF203(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF204() {
		Double a = MathsUtils.div("2", getPassF204(), getCountF204(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF205() {
		Double a = MathsUtils.div("2", getPassF205(), getCountF205(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF206() {
		Double a = MathsUtils.div("2", getPassF206(), getCountF206(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF207() {
		Double a = MathsUtils.div("2", getPassF207(), getCountF207(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public double getCountF200() {
		return MathsUtils.sum(getCountF201(), getCountF202(), getCountF203(),
				getCountF204(), getCountF205(), getCountF206(), getCountF207());
	}

	@Transient
	public double getPassF200() {
		return MathsUtils.sum(getPassF201(), getPassF202(), getPassF203(),
				getPassF204(), getPassF205(), getPassF206(), getPassF207());
	}

	@Transient
	public double getPassrateF200() {
		if (getCountF200() == 0) {
			return 0;
		} else {
			return MathsUtils.div("2", getPassF200(), getCountF200(),
					0.01);
		}
	}
	
	@Transient
	public String getGroupBy() {
		return this.groupBy;
	}

}
